package application;

import android.app.Application;

import com.lefull.lefullbase.base.LeFullBaseModule;
import com.lefull.lefullbase.utils.OkGoHelper.HTTPClientConfig;
import com.lefull.lefullbase.utils.OkGoHelper.InitInterface;
import com.lefull.lefullbase.utils.helper.DateHelper;
import com.lefull.lefullbase.utils.helper.P;
import com.lefull.lefullbase.utils.helper.StringHelper;
import com.lefull.lefullbase.utils.helper.To;

import net.TenantParserModel;

import java.util.HashMap;
import java.util.Map;

import constant.C;
import utils.LeFullMD5Utils;


public class ModuleTestApplication extends Application {
    @Override
    public void onCreate() {
        super.onCreate();
        //初始化网络框架
        initNet();
        //初始化项目基础模块
        LeFullBaseModule.getInstance().init(this);
    }

    private void initNet() {
        HTTPClientConfig.getInstance().init(C.base_url, new TenantParserModel(), new InitInterface() {
            @Override
            public Map<String, String> getHeader() {
                HashMap<String, String> header = new HashMap<>();
                if (!StringHelper.isStringNull(LeFullAppInfo.getmToken())) {
                    header.put(C.APP_TOKEN,LeFullAppInfo.getmToken());
                    header.put(C.TIMESTAMP, DateHelper.getTodayDateSimp());
                    header.put(C.SIGN, LeFullMD5Utils.md5Value(header));
                } else if (!StringHelper.isStringNull(P.getString(P.TOKEN))) {
                    header.put(C.APP_TOKEN, P.getString(P.TOKEN));
                    header.put(C.TIMESTAMP, DateHelper.getTodayDateSimp());
                    header.put(C.SIGN,  LeFullMD5Utils.md5Value(header)); //TODO:签名算法
                }
                header.put(C.CLIENT, "Android");
                header.put(C.APPTYPE,"1");
                return header;
            }

            @Override
            public Map<Integer, String> getErrorMap() {
                HashMap<Integer, String> defaultErrorMap = new HashMap<>();
                defaultErrorMap.put(-2, "呀，网络正在开小差！");
                return defaultErrorMap;
            }
        });
    }
}
